package com.xiaoye.qbproject.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiaoye.qbproject.domain.MqRead;
import com.xiaoye.qbproject.mapper.MqReadMapper;
import com.xiaoye.qbproject.service.MqReadService;
import com.xiaoye.qbproject.vo.ReadMsgVo;
import org.springframework.stereotype.Service;

/**
 * @author Administrator
 * @description 针对表【MQ_READ(mq消息已读)】的数据库操作Service实现
 * @createDate 2025-04-26 23:00:26
 */
@Service
public class MqReadServiceImpl extends ServiceImpl<MqReadMapper, MqRead>
        implements MqReadService {

    @Override
    public void readMsg(ReadMsgVo readMsgVo) {
        String msgId = readMsgVo.getMsgId();
        String type = readMsgVo.getType();
        String userId = readMsgVo.getUserId();

        // 先查询是否存在记录
        Long count = baseMapper.selectCount(Wrappers.lambdaQuery(MqRead.class)
                .eq(MqRead::getMsgId, msgId)
                .eq(MqRead::getUserId, userId)
        );
        if (count != 0) {
            return;
        }
        MqRead mqRead = new MqRead();
        mqRead.setMsgId(msgId);
        mqRead.setUserId(userId);
        mqRead.setType(type);
        baseMapper.insert(mqRead);

    }
}




